package com.heima.wemedia.controller.v1;

import com.heima.model.common.constants.wemedia.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDTO;
import com.heima.model.wemedia.dtos.WmNewsDTO;
import com.heima.model.wemedia.dtos.WmUserDTO;
import com.heima.wemedia.service.WmMaterialService;
import com.heima.wemedia.service.WmNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(value = "自媒体API",tags = "自媒体API")
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
   @Autowired
    WmMaterialService wmMaterialService;

   @Autowired
    WmNewsService wmNewsService;
@ApiOperation("上传素材")
@PostMapping("/upload_picture")

    ResponseResult uploadPicture(MultipartFile multipartFile){
    return  wmMaterialService.uploadPicture(multipartFile);
}
    @ApiOperation("查询素材列表")
    @PostMapping("/list")

    ResponseResult findList(@RequestBody WmMaterialDTO dto){
        return  wmMaterialService.findList(dto);
    }

    @ApiOperation(value="删除图片",notes = "根据ID删除素材,有关联的素材不可以删除")
    @GetMapping("/del_picture/{id}")

    ResponseResult delPicture(@PathVariable Integer id){
        return  wmMaterialService.delPicture(id);
    }

    @ApiOperation(value="取消收藏素材")
    @GetMapping("/cancel_collect/{id}")

    ResponseResult cancelCollectionMaterial(@PathVariable Integer id){
        return  wmMaterialService.upateStatus(id, WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }

    @ApiOperation(value="收藏素材")
    @GetMapping("/collect/{id}")

    ResponseResult CollectionMaterial(@PathVariable Integer id){
        return  wmMaterialService.upateStatus(id,WemediaConstants.COLLECT_MATERIAL);
    }

    @ApiOperation(value="根据id删除自媒体文章")
    @GetMapping("/del_news/{id}")

    ResponseResult delNews(@PathVariable Integer id){
        return  wmNewsService.delNews(id);
    }




}
